package com.wjm.multithreadingbreakpointcontinuedtransmission;

import android.Manifest;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import permissions.dispatcher.NeedsPermission;
import permissions.dispatcher.RuntimePermissions;

//必需
@RuntimePermissions
public class MainActivity extends AppCompatActivity {

    public static final String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setTitle(getString(R.string.single_thread_download));
        findViewById();

        //方便调试直接给权限不纠结
        MainActivityPermissionsDispatcher.NeedsPermissionWithCheck(MainActivity.this);
    }

    private void findViewById() {
        Button btn_single_thread_download = findViewById(R.id.btn_single_thread_download);
        btn_single_thread_download.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //单线程下载断点续传下载示例
                startActivity(new Intent(MainActivity.this,SingleThreadDownloadActivity.class));

            }
        });
    }

    //必需
    @NeedsPermission({Manifest.permission.WRITE_EXTERNAL_STORAGE })
    void NeedsPermission() {
        Toast.makeText(this, "NeedsPermission==>申请单个权限-READ_EXTERNAL_STORAGE-成功", Toast.LENGTH_SHORT).show();
    }

//    //可有
//    @Override
//    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
//        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
//        // NOTE: delegate the permission handling to generated method
//        //MainActivityPermissionsDispatcher类是要编译后才动态生成的
//        MainActivityPermissionsDispatcher.onRequestPermissionsResult(this, requestCode, grantResults);
//    }


}
